package com.lx.book.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lx.book.entity.Book;
import com.lx.book.mapper.BookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements BookService{
    @Autowired
    BookMapper bookMapper;
    @Override
    public List<Book> searchBook(Book book) {
        QueryWrapper queryWrapper=new QueryWrapper();
        if(book.getAuthor()!=null&&book.getAuthor()!=""){
            queryWrapper.like("author",book.getAuthor());
        }
        if(book.getName()!=null&&book.getName()!=""){
            queryWrapper.like("name",book.getName());
        }
        if(book.getCategory()!=null&&book.getCategory()!=""){
            queryWrapper.eq("category",book.getCategory());
        }
        return bookMapper.selectList(queryWrapper);
    }

    @Override
    public boolean addBook(Book book) {
        return bookMapper.addBook(book);
    }

    @Override
    public boolean delBook(Integer[] id) {
        return bookMapper.delBook(id);
    }

    @Override
    public Book all(Integer id) {
        return bookMapper.all(id);
    }

    @Override
    public boolean update(Book book) {
        return bookMapper.update(book);
    }
}
